<?php
namespace Home\Controller;

use Common\Controller\CommonController;

/**
 * 集采配置
 * @author 张亚伟 <zhangyw@zhijin101.com>
 */
class JcConfigController extends CommonController
{

    public function index()
    {
        // $map = [];
        // list($list, $page) = $this->lists('JcGift', $map, 'id asc');
        // $this->assign('page', $show);
        // $this->assign('list', $list);
        $this->display();
    }

    public function add()
    {
        
    }

    public function edit(){
        $id = I('id');
        $group = I('group');
        if (IS_POST) {
            $data = I('post.');
            $model = M('Config');
            $save_data = [];
            foreach ($data as $key => $value) {
                $model->where(['name'=>$key])->save(['value'=>html_entity_decode($value)]);
            }
            $this->ajaxReturn(array('s' => true, 'm' => '修改成功', 'url' => U('edit', ['group'=>$group])));
        } else {
            $config = M('Config')->where(['group' => $group, 'is_show'=>1])->order('sort desc,id asc')->select();
            $this->assign('config', $config);
            $this->assign('group', $group);
            $this->display();
        }
    }

    public function del()
    {

    }
}
